<template>
    <div>
        <div>
            <h2>添加分类</h2>
            <p>分类名称：<input type="text" v-model="cate_name"></p>
            <p>上级分类：
                <select v-model="cate_id">
                <option value="0">顶级分类</option>
                <option v-for="c in cate_list" :key="c.id" :value="c.id" v-if="c.cid=='null'">{{c.cate_name}}</option>
                </select></p>
            <p><button @click="add_cate">添加分类</button></p>
        </div>
    </div>
</template>

<script>
import axios from 'axios'
export default {
    data() {
        return { 
            base_url:'http://127.0.0.1:8000',
            cate_name:'',
            cate_id:'0',
            cate_list:[]
        }
    },
    methods: {
        add_cate(){
            let formdata= new FormData()
            formdata.append('cate_id',this.cate_id)
            formdata.append('cate_name',this.cate_name)

            axios({
                url:this.base_url + '/app03/cate_api',
                method:'post',
                data:formdata
            }).then(res=>{
                console.log(res.data)
            })

        },
        get_cate(){

            axios({
                url:this.base_url + '/app03/cate_api',
                method:'get'
            }).then(res=>{
                console.log(res.data)
                this.cate_list = res.data
            })
        }
    },
    created() {
        this.get_cate()
    }
}
</script>

<style>

</style>
